package nowcoder.offer;

import java.util.ArrayList;
import java.util.HashSet;

/**
 * 和为S的两个数字
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-08-28 14:52
 */
public class FindNumbersWithSum {

    public ArrayList<Integer> solution(int[] array,int sum){
        ArrayList<Integer> res = new ArrayList<>();
        if (array == null || array.length == 0)
            return res;

        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            set.add(array[i]);
        }
        for (int i = 0; i < array.length; i++) {
            if (set.contains(sum-array[i])){
                res.add(array[i]);
                res.add(sum-array[i]);
                break;
            }
        }

        return res;
    }

    public static void main(String[] args) {

    }
}
